class Newsletter < ActiveRecord::Base
  
  validates_presence_of :email

  before_create :generate_activation_key

  KIND = {
    :private => 1,
    :public => 2
  }

  def initialize(params = nil)
    super
    self.kind = KIND[:private]
  end

  def activate!
    if self.activated_at.blank?
      self.activated_at = Time.now
      self.activation_key = ""
      return self.save(false)
    else
      return false
    end
  end

  private

  def generate_activation_key
    self.activation_key = ActiveSupport::SecureRandom.hex(32)
  end

end